﻿using BLL.Origins;
using Model.Origins;
using PagedList;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using System.Drawing;
using Model.Sys;
using System.Data;
using Common;
using System.IO;
using Model;
using System.Net.Http;
using System.Text;
using System.Web.UI.WebControls;
using System.Drawing;
using System.Drawing.Imaging;
 
namespace DAGG.Controllers.SY
{
    public class JtsyController : BaseController
    {
        OriginsTempletBLL bll = new OriginsTempletBLL();
        //
        // GET: /Jtsy/
        public ActionResult Index(int page = 1)
        {

            IPagedList<OriginsTempletModel> modelInfoList = bll.GetList("","").ToPagedList(page, 10);
            //将数据分页后返回页面（这里可以在取数据的时候先分页后，再使用ToPagedList实现分页
            ViewBag.MyPageList = modelInfoList;
            return View();
        }
        /// <summary>
        /// 编辑界面
        /// </summary>
        /// <returns></returns>
        public ActionResult Edit()
        {
            return View();

        }
        /// <summary>
        /// 新增编辑界面
        /// </summary>
        /// <returns></returns>
        public ActionResult EditPhone(string oper, int tempId = 0)
        {
            string editContent = string.Empty;
            if (oper == "edit")
            {//编辑操作
                //根据编号获取对应的信息
                DataTable dt = bll.GetTempletById(tempId);
                ViewData["Title"] = dt.Rows[0]["Name"];
                if (dt.Rows[0]["ImgUrl"].ToString() == "")
                ViewData["EditContent"] = dt.Rows[0]["Content"];
                else ViewData["EditContent"] = @"<img src='" + dt.Rows[0]["ImgUrl"].ToString() + "' max-width:100%/>" + dt.Rows[0]["Content"].ToString();
                ViewData["Action"] = tempId;
            }
          
            return View();

        }

        /// <summary>
        /// 保存数据
        /// </summary>
        /// <returns></returns>
        [ValidateInput(false)]
        [HttpPost]
        public ActionResult SaveData(string Content, string title)
        {
            SysUserModel userModel = base.GetUserInfo();
            //获取到编辑框中的值 向表Origins_OriginsTemplet 中插入值信息
            bll.SaveData(Content, title,"", userModel);
            return Redirect("/Product/Index");
        }
      



        [ValidateInput(false)]
        [HttpPost]
        public ActionResult NewSaveData(string oper, string Content, int tempId, string title, string imgUrl)
        {


            SysUserModel userModel = base.GetUserInfo();

            if (oper == "add")
            {

                ResultEntity entity = bll.SaveData(Content, title, imgUrl, userModel);
                int id = entity.Id;
                //获取ID
                return Json(id);
            }
            else
            {
                int i = bll.UpdateTempletById(tempId, Content, title, imgUrl);
                return Json(i);
            }

        }
      
    }
}